package com.sxm.yiwei.adapters;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.HomeSearchActivity;
import com.sxm.yiwei.beans.ShopContent;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.x;

import java.util.List;

/**
 * Created by KuKa on 2017/8/4.
 * 搜索店铺列表
 */

public class SearchShopAdapter extends BaseAdapter {
    Context context;
    public List<ShopContent.DataBean> list;
    public SearchShopAdapter(Context context, List<ShopContent.DataBean> list) {
        this.context = context;
                this.list =list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.search_listitem1,null);
            holder = new ViewHolder();

            holder.listname = (TextView) view.findViewById(R.id.search_itemshop_name);
            holder.head = (ImageView) view.findViewById(R.id.search_itemshop_head);
            holder.listpeople = (TextView) view.findViewById(R.id.search_itemshop_number);
            holder.listdistance = (TextView) view.findViewById(R.id.search_itemshop_distance);

            holder.pinglun1 = (ImageView) view.findViewById(R.id.search_itemshop_img1);
            holder.pinglun2 = (ImageView) view.findViewById(R.id.search_itemshop_img2);

            holder.pinglun3 = (ImageView) view.findViewById(R.id.search_itemshop_img3);
            holder.pinglun4 = (ImageView) view.findViewById(R.id.search_itemshop_img4);
            holder.xinnum = (TextView) view.findViewById(R.id.search_itemshop_xinnum);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.listname.setText(list.get(position).getName());

        holder.listdistance.setText(list.get(position).getDistance()+" 公里");
        holder.listpeople.setText("总成交: "+list.get(position).getVolume()+" 单");
        int type = list.get(position).getType();
        int gradeCode = list.get(position).getGradeCode();
        int sellGrade = list.get(position).getSellGrade();
        boolean isInsurance = list.get(position).isIsInsurance();
        if (isInsurance){
            holder.pinglun2.setImageResource(R.mipmap.baocai);
        }else {
            holder.pinglun2.setImageResource(R.mipmap.baohui);
        }
        if (type==1){
            holder.pinglun3.setVisibility(View.GONE);
        }else {
            holder.pinglun3.setImageResource(R.mipmap.qiye);
        }

        switch (gradeCode){
            case 1:
                holder.pinglun4.setImageResource(R.mipmap.g10);
                break;
            case 2:
                holder.pinglun4.setImageResource(R.mipmap.g1);
                break;
            case 3:
                holder.pinglun4.setImageResource(R.mipmap.g2);
                break;
            case 4:
                holder.pinglun4.setImageResource(R.mipmap.g3);
                break;
            case 5:
                holder.pinglun4.setImageResource(R.mipmap.g4);
                break;
            case 6:
                holder.pinglun4.setImageResource(R.mipmap.g6);
                break;
            case 7:
                holder.pinglun4.setImageResource(R.mipmap.g5);
                break;
            case 8:
                holder.pinglun4.setImageResource(R.mipmap.g7);
                break;
            case 9:
                holder.pinglun4.setImageResource(R.mipmap.g8);
                break;
            case 10:
                holder.pinglun4.setImageResource(R.mipmap.g9);
                break;

        }
        switch (sellGrade){
            case 1:
                holder.pinglun1.setImageResource(R.mipmap.xin);
                break;
            case 2:
                holder.xinnum.setText("2");
                holder.pinglun1.setImageResource(R.mipmap.xin);
                break;
            case 3:
                holder.xinnum.setText("3");
                holder.pinglun1.setImageResource(R.mipmap.xin);
                break;
            case 4:
                holder.xinnum.setText("4");
                holder.pinglun1.setImageResource(R.mipmap.xin);
                break;
            case 5:
                holder.xinnum.setText("5");
                holder.pinglun1.setImageResource(R.mipmap.xin);
                break;
            case 6:
                holder.pinglun1.setImageResource(R.mipmap.zuan);
                break;
            case 7:
                holder.xinnum.setText("2");
                holder.pinglun1.setImageResource(R.mipmap.zuan);
                break;
            case 8:
                holder.xinnum.setText("3");
                holder.pinglun1.setImageResource(R.mipmap.zuan);
                break;
            case 9:
                holder.xinnum.setText("4");
                holder.pinglun1.setImageResource(R.mipmap.zuan);
                break;
            case 10:
                holder.xinnum.setText("5");
                holder.pinglun1.setImageResource(R.mipmap.zuan);
                break;
            case 11:

                holder.pinglun1.setImageResource(R.mipmap.gaun);
                break;
            case 12:
                holder.xinnum.setText("2");
                holder.pinglun1.setImageResource(R.mipmap.gaun);
                break;
            case 13:
                holder.xinnum.setText("3");
                holder.pinglun1.setImageResource(R.mipmap.gaun);
                break;
            case 14:
                holder.xinnum.setText("4");
                holder.pinglun1.setImageResource(R.mipmap.gaun);
                break;
            case 15:
                holder.xinnum.setText("5");
                holder.pinglun1.setImageResource(R.mipmap.gaun);
                break;
            case 16:
                holder.pinglun1.setImageResource(R.mipmap.jinguan);
                break;
            case 17:
                holder.xinnum.setText("2");
                holder.pinglun1.setImageResource(R.mipmap.jinguan);
                break;
            case 18:
                holder.xinnum.setText("3");
                holder.pinglun1.setImageResource(R.mipmap.jinguan);
                break;
            case 19:
                holder.xinnum.setText("4");
                holder.pinglun1.setImageResource(R.mipmap.jinguan);
                break;
            case 20:
                holder.xinnum.setText("5");
                holder.pinglun1.setImageResource(R.mipmap.jinguan);
                break;
        }


        x.image().bind(holder.head, InternetAddressUtis.IMG_URL+list.get(position).getAvatar());
        return view;
    }
    class ViewHolder{
        ImageView pinglun,pinglun1,pinglun2,pinglun3,pinglun4,head;
        TextView listname,xinnum,contenttext,listdistance,listpeople;
    }
}
